/**
 * 统一响应格式
 */

class ApiResponse {
  constructor(code, data, message, success) {
    this.code = code;
    this.data = data;
    this.message = message;
    this.success = success;
  }
}

class ErrorResponse {
  constructor(code, message) {
    this.code = code;
    this.message = message;
  }
}

/**
 * 成功响应
 * @param {*} data 响应数据
 * @param {string} message 响应消息
 * @param {number} code 响应码
 * @returns {ApiResponse}
 */
const success = (data = null, message = '操作成功', code = 200) => {
  return new ApiResponse(code, data, message, true);
};

/**
 * 错误响应
 * @param {string} message 错误消息
 * @param {number} code 错误码
 * @returns {ErrorResponse}
 */
const error = (message = '操作失败', code = 500) => {
  return new ErrorResponse(code, message);
};

module.exports = {
  success,
  error,
  ApiResponse,
  ErrorResponse
}; 